import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    loginInfo: {
      userId: null,
      userName: null,
      loginStatus: false
    }
  },
  getters: {
    fullName: state => `${state.userName} (${state.userId})`
  },
  mutations: {
    // 更新登录信息的 Mutation
    UPDATE_LOGIN_INFO(state, loginData) {
      state.loginInfo = loginData;
    }
  },
  actions: {
    fetchUserInfo({ commit }) {
      // 模拟异步获取用户信息的操作
      setTimeout(() => {
        commit('UPDATE_USER_INFO', { userId: 123, userName: 'John' });
      }, 1000);
    }

  },
  modules: {
    fullName: state => `${state.userName} (${state.userId})`
  }
})
